package work.base.data.date.joda.time;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;

import java.time.Duration;
import java.time.Period;
import java.util.TimeZone;

/**
 * @author shenminglong@kedacom.com
 * @date 2021-11-30
 *
 * org.joda.time 基本使用
 */
public class JodaTimeTest {

    public static void main(String[] args) {

        // Joda-Time
        DateTime now = new DateTime();
        System.out.println(now);
        DateTime tomorrow = now.plusDays(1);
        System.out.println(tomorrow);

        //判断时间跨度是否包含当前时间,某个时间
        Interval interval = new Interval(new DateTime(2017, 1, 1, 0, 0, 0),new DateTime(2022, 3, 30, 0, 0, 0));
        System.out.println(interval.containsNow());
        boolean contained = interval.contains(new DateTime("2012-03-01"));
        System.out.println(contained);

        Period p = Period.of(1,1,1);
        System.out.println("相隔的天："+p.getDays());

        Duration duration = Duration.ofMillis(1000L);
        System.out.println(duration);

        // 获得日本时区的时间
        DateTimeZone gmt = DateTimeZone.forID("Japan");
        DateTime dateTime = DateTime.now().toDateTime(gmt);
        System.out.println(dateTime);

        // 指定时区构造时间
        // DateTime构造函数指定区时
        DateTime dateTime11 = new DateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Japan")));
        System.out.println(dateTime11);
        System.out.println(dateTime11.toDate());
    }
}
